export const useOnReachBottom = ({ loadMore }) => {
  let observe: any = null
  const loadMoreEl = ref(null)
  const onObserver = () => {
    observe = new IntersectionObserver((entries) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          console.log('元素触底',entry, loadMoreEl.value)
          loadMore?.()
        }
      })
    })
    observe.observe(loadMoreEl.value!)
  }
  const unObserver = () => {
    observe.unobserve(loadMoreEl.value!)
  }
  onMounted(() => {
    onObserver()
  })
  onBeforeUnmount(() => {
    unObserver()
  })
  return {
    loadMoreEl
  }
}
